package leetcode.sword;

import datastruct.list.ListNode;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;

public class Solution06 {

    public int[] reversePrint(ListNode head) {

        if(head==null) return new int[0];

        int[] next = reversePrint(head.next);

        int len = next.length;

        int[] tmp = new int[len+1];

        System.arraycopy(next,0,tmp,0,len);

        tmp[len] = head.val;

        return tmp;
    }

    static int[] res = null;

    public int[] reversePrint1(ListNode head) {
        reverPrint(head,0);
        return res;
    }

    public void reverPrint(ListNode head, int idx){
        //idx标识这是链表第几个元素

        //遍历到最后再初始化
        if(head==null){
            res = new int[idx];
            return;
        }
        //往后走
        reverPrint(head.next,idx+1);
        //其他节点开始放入
        int arrLen = res.length-1;
        res[arrLen-idx] = head.val;
    }

}
